package com.xjzd.jvm;

import java.lang.ref.WeakReference;
import java.util.concurrent.TimeUnit;

public class WeakReferenceDemo {

    private static final class User {}

    public static void main(String[] args) throws InterruptedException {
        WeakReference<User> weakReference = new WeakReference<>(new User());
        System.out.println(weakReference.get());
        System.gc();
        TimeUnit.SECONDS.sleep(3); // wait gc thread run
        System.out.println(weakReference.get()); // null
    }
}
